#include "../head.h"

class foo
{
public:
    foo(int other) : m(other) {}

    ~foo()
    {
        cout << "foo deconstructor" << endl;
    }
private:
    int m;
};

class test1
{
public:
    test1(foo &other) : obj(other) {}
private:
    foo &obj;
};

class test2
{
public:
    test2(foo &other) : obj(other) {}
private:
    foo obj;
};

int main()
{
    foo a(1);
    cout << "test1 start" << endl;
    {
        // test1中包含foo引用成员变量，不会调用foo析构函数
        test1 t(a);
    }
    cout << "test1 end" << endl;

    cout << "test2 start" << endl;
    {
        // test2中包含foo成员变量，会调用foo析构函数
        test2 t(a);
    }
    cout << "test2 end" << endl;
}